﻿// www.2.0.cpp : 定义应用程序的入口点。
//

#include "framework.h"
#include "www.2.0.h"
#include <math.h>

#include <OleCtl.h>
#include <combaseapi.h>
#include <string>

#define MAX_LOADSTRING 100
//可调整的常量：
#define Speed 5//可莉速度
#define KleeRelativeSize 7//可莉相对大小
#define FrameRate 30//帧率
#define HowMathMonsters 200//怪物量


//特殊点坐标
#define Start_x 0//屏幕中的位置
#define Start_y 0
#define Centre_x 950
#define Centre_y 495
#define End_x 1900
#define End_y 990
#define RCStart_x -5000//刷新范围
#define RCStart_y -5000
#define RCEnd_x 6900
#define RCEnd_y 5990
#define FindStart_x 300//开始进攻范围
#define FindStart_y 50
#define FindEnd_x 1500
#define FindEnd_y 940
//计时器
#define RCTimer 10
#define RCIPictureTimer 11
#define _1sTimer 12
#define WalkTimer 1
#define JumpTimer 2
#define AaAttackTimer 3
#define Fire_aAttackTimer 4
#define Hurt_MathTimer 5

#define T_Walk 0
#define T_aAttrack 1
#define T_EscapeS 2
//判断
#define Left 0
#define Right 1
#define WALK_STAY 0//WALK用于分x和y轴的运动,加起来后5右下,6左下,9右上,10右下,0~15内其他数无意义,但部分有效果
#define WALK_RIGHT 1
#define WALK_LEFT 2
#define WALK_DOWN 4
#define WALK_UP 8
#define WALK_Stay WALK_STAY
#define WALK_Right WALK_RIGHT
#define WALK_Left WALK_LEFT
#define WALK_Up WALK_UP
#define WALK_Down WALK_DOWN
#define No 0
#define Yes 1
#define ReadyaAttack 1//用于攻击判断
#define aAttack 2
#define AAttack 3
#define EndaAttack 4
#define EA_No 0//无
#define EA_Ice 1//冰
#define EA_Fire 2//火
#define EA_Water 3//水
#define EA_IceFrozen 4//冻结
#define EA_Electricity 5//雷
#define EA_Wind 6//风
#define EA_Rock 7//岩
#define EA_WaterAndElectricity 8//水雷共存
#define EA_Grass 9//草
//#define EA_GrassIce 10//冰草共存
//#define EA_IceGrass EA_GrassIce
#define EA_Burning 11//燃烧
//#define EA_WaterIce 12//水草共存
//#define EA_GrassWater EA_WaterGrass
//#define EA_ElectricityGrass 14//雷草共存
//#define EA_GrassElectricity EA_ElectricityGrass
#define Hide 0//不动
#define Outgoing 1//靠近
//其他定义
#define EA_Infinite 10000
#define Bodyx Centre_x - 9 * KleeRelativeSize//用于得到可莉大小
#define Bodyy Centre_y - 11 * KleeRelativeSize
#define Bodycx 18 * KleeRelativeSize
#define Bodycy 22 * KleeRelativeSize
#define Facex Centre_x - 5 * KleeRelativeSize
#define Facex_Right Centre_x - 1 * KleeRelativeSize
#define Facey Centre_y - 3 * KleeRelativeSize
#define Facecx 6 * KleeRelativeSize
#define Facecy 4 * KleeRelativeSize


// 全局变量:
int KleeFloatx = 0, KleeFloaty = 0;//可莉位置浮动
int KleePlacex = 0, KleePlacey = 0;//可莉相对坐标
int KleeBlood = 16000;//可莉血量
int EscapeTime[10] = {0,0,0,0,0,0,0,0,0,0};//判断可莉走跑时上下浮动状态,攻击移动等
int KleeWalkFacex = WALK_STAY, KleeWalkFacey = WALK_STAY;//可莉走路方向
int KleeFacex = WALK_LEFT, KleeFacey = WALK_LEFT;//可莉真正面向方向
int Face = Left;//可莉图片面向方向
int Emotion = 0;//可莉表情
bool ReflectExtraMassage = FALSE;//F5
float Reflect = FALSE, DeBug = FALSE;//用于调试
int RandPointx[1000], RandPointy[1000],Long = 0;
int* pRandPointx = &RandPointx[0], * pRandPointy = &RandPointy[0], * pLong = &Long;//随机数点，指针指向的点是NULL
int AaAttack_is = No;
int AttackFacex = WALK_STAY, AttackFacey = WALK_STAY;//攻击时的方向
int AttackPointx[100], AttackPointy[100], AttackPointcx[100] = { 30 }, AttackPointcy[100] = { 30 };//攻击相对坐标
int KillMonsters = 0;//杀死敌人数
int Hurtx = 0, Hurty = 0;//受伤数字

HINSTANCE hInst;                                // 当前实例
WCHAR szTitle[MAX_LOADSTRING];                  // 标题栏文本
WCHAR szWindowClass[MAX_LOADSTRING];            // 主窗口类名
RECT rc;

// 此代码模块中包含的函数的前向声明:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
IPicture* GetDisplayImage(LPCTSTR szImagePath);
void RenderPicture(IPicture* pIPicture, HDC hdc, int x, int y, int cx, int cy);
void MakeRandPoint(int HowMath, bool InReflect);
void RCReplaceRandPoint();
void MakeAMonster();//为当前pMonster指向的指针随机赋值
void Move(int* px, int* py, int HowMath, int Walk_x, int Walk_y);
int EA_Reaction(int Attack, int* pEA_ElementAttachment, float* pEA_HowMath, int EA_Attack, float EA_HowMathAttack);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: 在此处放置代码。
    srand(GetTickCount());

    // 初始化全局字符串
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_WWW20, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // 执行应用程序初始化:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WWW20));

    MSG msg;


    // 主消息循环:
    while (GetMessage(&msg, nullptr, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}



//
//  函数: MyRegisterClass()
//
//  目标: 注册窗口类。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEXW wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WWW20));
    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_WWW20);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassExW(&wcex);
}

//
//   函数: InitInstance(HINSTANCE, int)
//
//   目标: 保存实例句柄并创建主窗口
//
//   注释:
//
//        在此函数中，我们在全局变量中保存实例句柄并
//        创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // 将实例句柄存储在全局变量中

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目标: 处理主窗口的消息。
//
//  WM_COMMAND  - 处理应用程序菜单
//  WM_PAINT    - 绘制主窗口
//  WM_DESTROY  - 发送退出消息并返回
//
//
//图片变量
IPicture* Black;
IPicture* Green;
IPicture* Rad;
IPicture* Yellow;
IPicture* KleeBody[2];
IPicture* KleeFace[2][4];
IPicture* Grass;
IPicture* Tips;
IPicture* Klees_aAttack;//普通攻击
/*IPicture* Klees_FireFlower;//爆裂火花
IPicture* Klees_AAttack;//重击
IPicture* Klees_EAttack;//蹦蹦炸弹
IPicture* Klees_eAttack;//诡雷
IPicture* Klees_QAttrack;//轰轰火花*/
IPicture* Klees_Boom;
IPicture* Slime_Grass_Hide[2];//隐藏草史莱姆
IPicture* Slime_Grass_Outgoing[2];//出来草史莱姆
IPicture* Slime_Ice[2];//冰史莱姆

/*
HDC         g_hMemDc = NULL;     // Memory DC for the back buffer.
HBITMAP     g_hBackBuffer = NULL;     // Back buffer bitmap.

HDC GetBackBuffer(HWND hWnd)
{
    // !!! Create and return a back-buffer for double-buffer painting.
    // If the memory DC is already initialized, simply return.
    if (g_hMemDc)
    {
        return g_hMemDc;
    }

    // Initialize the memory DC and a back buffer bitmap to write on.
    RECT client;
    ::GetClientRect(hWnd, &client);

    int width = client.right - client.left;
    int height = client.bottom - client.top;

    // Get a DC from the target paint location to be sure a compatible 
    // drawing context is created.
    HDC hDc = ::GetDC(hWnd);

    // Create the Memory DC to be compatible with the target window.
    g_hMemDc = ::CreateCompatibleDC(hDc);

    // It is important the BITMAP be created to be compatible as well.
    // This will insure the correct bit-color depth and other parameters
    // match the target DC.
    g_hBackBuffer = ::CreateCompatibleBitmap(hDc, width, height);

    // Select the bitmap into the memory DC.
    // Otherwise there will be no buffer for the the operations to write into.
    ::SelectObject(g_hMemDc, g_hBackBuffer);

    // Release handles to target window 
    ::ReleaseDC(hWnd, hDc);

    return g_hMemDc;
}


void FlushBackBuffer()
{
    if (g_hMemDc)
    {
        ::DeleteDC(g_hMemDc);
        g_hMemDc = NULL;
    }

    if (g_hBackBuffer)
    {
        ::DeleteObject(g_hBackBuffer);
        g_hBackBuffer = NULL;
    }
}
*/

void EXIT() {
    if (Black != NULL)
        Black->Release();
    if (Green != NULL)
        Green->Release();
    if (Rad != NULL)
        Rad->Release();
    if (Yellow != NULL)
        Yellow->Release();
    if (KleeBody[0] != NULL)
        KleeBody[0]->Release();
    if (KleeBody[1] != NULL)
        KleeBody[1]->Release();
    for (int i = 0; i <= 1; i++) {
        for (int j = 0; j <= 3; j++) {
            if (KleeFace[i][j] != NULL)
                KleeFace[i][j]->Release();
        }
    }
    if (Grass != NULL)
        Grass->Release();
    if (Tips != NULL)
        Tips->Release();
    if (Klees_aAttack != NULL)
        Klees_aAttack->Release();
    if (Slime_Grass_Hide[Left] != NULL)
        Slime_Grass_Hide[Left]->Release();
    if (Slime_Grass_Hide[Right] != NULL)
        Slime_Grass_Hide[Right]->Release();
    if (Slime_Grass_Outgoing[Left] != NULL)
        Slime_Grass_Outgoing[Left]->Release();
    if (Slime_Grass_Outgoing[Right] != NULL)
        Slime_Grass_Outgoing[Right]->Release();
    if (Slime_Ice[Left] != NULL)
        Slime_Ice[Left]->Release();
    if (Slime_Ice[Right] != NULL)
        Slime_Ice[Right]->Release();    
}
struct Monsters {
    int Blood;
    int cx;
    int cy;
    int EA_ElementAttachment;//元素附着
    float EA_HowMath;//元素附着量0.5弱弱, 1弱, 2中, 4强, 8超强
    bool Face;
    int MaxBlood;
    IPicture* Name[2];
    int State;//状态
    int x;
    int y;
};
struct Monsters Monster[HowMathMonsters], * pMonster = &Monster[0];
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_CREATE:
        //MakeRandPoint(200, FALSE);
        SetTimer(hWnd, RCTimer, int(1000 / FrameRate), NULL);
        SetTimer(hWnd, RCIPictureTimer, 10000, NULL);
        SetTimer(hWnd, _1sTimer, 1000, NULL);
       
        {

            TCHAR szFilePath[MAX_PATH];

            GetModuleFileName(NULL, szFilePath, MAX_PATH);

            TCHAR* pszTemp = _tcsrchr(szFilePath, _T('\\'));
            pszTemp[1] = '\0';

            std::wstring strPicPath;

            strPicPath = szFilePath;
            strPicPath += _T("材料\\");

            std::wstring strPicFullPath;

            strPicFullPath = strPicPath + _T("Black.jpg");
            Black = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("Green.jpg");
            Green = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("Rad.jpg");
            Rad = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("Yellow.jpg");
            Yellow = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("可莉9：11.jpg");
            KleeBody[Left] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("可莉右9：11.jpg");
            KleeBody[Right] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("睁眼闭嘴可莉脸3：2.jpg");
            KleeFace[Left][0] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("睁眼闭嘴可莉脸右3：2.jpg");
            KleeFace[Right][0] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("闭眼张嘴可莉脸3：2.jpg");
            KleeFace[Left][1] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("闭眼张嘴可莉脸右3：2.jpg");
            KleeFace[Right][1] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("闭眼微笑可莉脸3：2.jpg");
            KleeFace[Left][2] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("闭眼微笑可莉脸右3：2.jpg");
            KleeFace[Right][2] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("单眼微笑可莉脸3：2.jpg");
            KleeFace[Left][3] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("单眼微笑可莉脸右3：2.jpg");
            KleeFace[Right][3] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("草10：1.jpg");
            Grass = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("空告示牌17：13.jpg");
            Tips = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("小炸弹1：1.jpg");
            Klees_aAttack = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("爆炸5：3.jpg");
            Klees_Boom = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("隐藏小草史莱姆2：1.jpg");
            Slime_Grass_Hide[Left] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("隐藏小草史莱姆右2：1.jpg");
            Slime_Grass_Hide[Right] = GetDisplayImage(strPicFullPath.c_str());
           
            strPicFullPath = strPicPath + _T("小草史莱姆10：11.jpg");
            Slime_Grass_Outgoing[Left] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("小草史莱姆右10：11.jpg");
            Slime_Grass_Outgoing[Right] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("冰史莱姆25：16.jpg");
            Slime_Ice[Left] = GetDisplayImage(strPicFullPath.c_str());

            strPicFullPath = strPicPath + _T("冰史莱姆右25：16.jpg");
            Slime_Ice[Right] = GetDisplayImage(strPicFullPath.c_str());

            ///其实可以把上面的写出一个函数

        }
        

        for (int i = 0; i < HowMathMonsters; i++) {
            MakeAMonster();
            pMonster++;
        }
        pMonster = &Monster[0];//重置指针

        break;
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            // 分析菜单选择:
            switch (wmId)
            {
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_LBUTTONDOWN:
        AaAttack_is = ReadyaAttack;
        if (AaAttack_is == No)
            SetTimer(hWnd, AaAttackTimer, 600, NULL);
        break;
    case WM_LBUTTONUP:
        AttackFacex = KleeFacex;
        AttackFacey = KleeFacey;
        AttackPointx[0] = Centre_x + KleePlacex;
        AttackPointy[0] = Centre_y + KleePlacey;
        KillTimer(hWnd, AaAttackTimer);
        if (AaAttack_is == ReadyaAttack) {
            SetTimer(hWnd, Fire_aAttackTimer, 10, NULL);
            AaAttack_is = aAttack;
        }
        EscapeTime[T_aAttrack] = 0;
        break;
    case WM_KEYFIRST:
        switch (wParam)
        {
        case 'D':
        case VK_RIGHT:
            Emotion = 1;
            Face = Right;
            KleeWalkFacex = WALK_RIGHT;
            KleeFacex = KleeWalkFacex;
            SetTimer(hWnd, WalkTimer, Speed, NULL);
            break;
        case 'A':
        case VK_LEFT:
            Emotion = 1;
            Face = Left;
            KleeWalkFacex = WALK_LEFT;
            KleeFacex = KleeWalkFacex;
            SetTimer(hWnd, WalkTimer, Speed, NULL);
            break;
        case 'S':
        case VK_DOWN:
            Emotion = 1;
            KleeWalkFacey = WALK_DOWN;
            KleeFacey = KleeWalkFacey;
            SetTimer(hWnd, WalkTimer, Speed, NULL);
            break;
        case 'W':
        case VK_UP:
            Emotion = 1;
            KleeWalkFacey = WALK_UP;
            KleeFacey = KleeWalkFacey;
            SetTimer(hWnd, WalkTimer, Speed, NULL);
            break;
        default:
            break;
        }
        break;
    case WM_KEYUP:
        switch (wParam)
        {
        case '1':
            Emotion = 0;
            break;
        case '2':
            Emotion = 1;
            break;
        case '3':
            Emotion = 2;
            break;
        case '4':
            Emotion = 3;
            break;
        case VK_F5:
            if (ReflectExtraMassage)
                ReflectExtraMassage = FALSE;
            else
                ReflectExtraMassage = TRUE;
            break;
        case 'D':
        case VK_RIGHT:
        case 'A':
        case VK_LEFT:
            KleeFacex = KleeWalkFacex;
            KleeWalkFacex = WALK_STAY;
            Emotion = 0;
            KleeFloatx = 0;
            KleeFloaty = 0;
            EscapeTime[T_Walk] = 0;
            KillTimer(hWnd, WalkTimer);
        case 'S':
        case VK_DOWN:
        case 'W':
        case VK_UP:
            KleeFacey = KleeWalkFacey;
            KleeWalkFacey = WALK_STAY;
            Emotion = 0;
            KleeFloatx = 0;
            KleeFloaty = 0;
            EscapeTime[T_Walk] = 0;
            KillTimer(hWnd, WalkTimer);
            break;
        default:
            break;
        }
        break;

    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        TCHAR Xname[100];
        HDC hdc = BeginPaint(hWnd, &ps);
        // TODO: 在此处添加使用 hdc 的任何绘图代码...
        ////////////////////////////////////////////////////////

        //::SetBkMode(hdcOrg, TRANSPARENT);
        //SetBkColor(hdcOrg, RGB(255, 255, 255));

        //HDC hdc = GetBackBuffer(hWnd);

        //HDC hdc = hdcOrg;

        //::SetBkMode(hdc, TRANSPARENT);
        //RECT rcClient;
        //GetClientRect(hWnd, &rcClient);

        //HBRUSH hBrushBg = CreateSolidBrush(RGB(255, 255, 255));
        //FillRect(hdc, &rcClient, hBrushBg);

        /*
        if (Grass != NULL)
            RandGeneration(Grass, hdc, 15, 5, Centre_x - 200, Centre_y - 200, Centre_x + 200, Centre_y + 200, 300, 60, 6);
            */
            //else if(Klees_AAttack != 0 && AaAttack_is == AAttack)
        for (int i = 0; i < HowMathMonsters; i++) {//以下为怪物判断
            if (pMonster->Name != NULL && (pMonster->x - KleePlacex + pMonster->cx) >= Start_x && (pMonster->x - KleePlacex) <= End_x && (pMonster->y - KleePlacey + pMonster->cy) >= Start_y && (pMonster->y - KleePlacey) <= End_y) {
                if ((pMonster->x - KleePlacex + pMonster->cx) >= FindStart_x && (pMonster->x - KleePlacex) <= FindEnd_x && (pMonster->y - KleePlacey + pMonster->cy) >= FindStart_y && (pMonster->y - KleePlacey) <= FindEnd_y) {//是否在警戒线以内
                    if (pMonster->State == Outgoing) {
                        if ((pMonster->x - KleePlacex + pMonster->cx / 2) <= Centre_x) {//逐渐逼近人
                            pMonster->x += 3;
                            pMonster->Face = Right;
                        }
                        else {
                            pMonster->x -= 3;
                            pMonster->Face = Left;
                        }
                        if ((pMonster->y - KleePlacey) <= Centre_y)
                            pMonster->y += 3;
                        else
                            pMonster->y -= 3;
                        //攻击：
                        if ((pMonster->x - KleePlacex + pMonster->cx) > Bodyx && (pMonster->x - KleePlacex) < (Bodyx + Bodycx) && (pMonster->y - KleePlacey + pMonster->cy) > Bodyy && (pMonster->y - KleePlacey) < (Bodyy + Bodycy)) {//攻击
                            KleeBlood -= 37;
                            if (KleeBlood <= 0) {
                                KleePlacex = 0;
                                KleePlacey = 0;
                                KillTimer(hWnd, RCTimer);
                                KillTimer(hWnd, RCIPictureTimer);
                                KillTimer(hWnd, _1sTimer);
                                if (MessageBox(hWnd, _T("是否回到原点重来？不是的话就给你退出"), _T("你死了"), MB_YESNO) == IDYES) {
                                    SetTimer(hWnd, RCTimer, int(1000 / FrameRate), NULL);
                                    SetTimer(hWnd, RCIPictureTimer, 10000, NULL);
                                    SetTimer(hWnd, _1sTimer, 1000, NULL);
                                    KleeBlood = 16000;
                                    pMonster = &Monster[0];
                                    EscapeTime[T_EscapeS] = 0;
                                    for (int i = 0; i < HowMathMonsters; i++) {
                                        MakeAMonster();
                                        pMonster++;
                                    }
                                    pMonster = &Monster[0];//重置指针
                                    break;
                                }
                                else {
                                    swprintf(Xname, _T("存活时间：%ds\n杀死敌人数：%d\n"), EscapeTime[T_EscapeS], KillMonsters);
                                    MessageBox(hWnd, Xname, _T("你死了"), MB_OK);
                                    EndPaint(hWnd, &ps); 
                                    //PostQuitMessage(0);
                                    //EndDialog(hWnd, 0);
                                    PostMessage(hWnd, WM_CLOSE, 0, 0);
                                    break;
                                }
                            }
                        }
                    }
                    //被攻击：
                    if ((pMonster->x + pMonster->cx) > AttackPointx[0] && pMonster->x < (AttackPointx[0] + AttackPointcx[0]) && (pMonster->y + pMonster->cy) > AttackPointy[0] && pMonster->y < (AttackPointy[0] + AttackPointcy[0]) && AaAttack_is == aAttack) {//被攻击
                        pMonster->Blood -= 4000;
                        EscapeTime[T_aAttrack] = 29;
                        if (pMonster->Blood <= 0) {
                            MakeAMonster();
                            KillMonsters++;
                        }
                        if (pMonster->State == Hide && pMonster->Name[Left] == Slime_Grass_Hide[Left]) {//为了草史莱姆
                            pMonster->State = Outgoing;
                            pMonster->cx = 125;
                            pMonster->cy = 120;
                            pMonster->Name[Left] = Slime_Grass_Outgoing[Left];
                            pMonster->Name[Right] = Slime_Grass_Outgoing[Right];
                        }
                    }
                }
                if (Black != NULL)//血条
                    RenderPicture(Black, hdc, pMonster->x - KleePlacex, pMonster->y - KleePlacey - 20, pMonster->cx, 5);
                if (Rad != NULL)
                    RenderPicture(Rad, hdc, pMonster->x - KleePlacex, pMonster->y - KleePlacey - 20, pMonster->cx * pMonster->Blood / pMonster->MaxBlood, 5);
            }
            if(pMonster->Name[pMonster->Face] != NULL)
                RenderPicture(pMonster->Name[pMonster->Face], hdc, pMonster->x - KleePlacex, pMonster->y - KleePlacey, pMonster->cx, pMonster->cy);
            pMonster++;
        }
        pMonster = &Monster[0];//重置指针


        if (KleeBody[Face] != NULL)//可莉
            RenderPicture(KleeBody[Face], hdc, Bodyx + KleeFloatx, Bodyy + KleeFloaty, Bodycx, Bodycy);
        if (KleeFace[Face][Emotion] != NULL) {
            if (Face == Right) {
                RenderPicture(KleeFace[Face][Emotion], hdc, Facex_Right + KleeFloatx, Facey + KleeFloaty, Facecx, Facecy);
            }
            else if (Face == Left) {
                RenderPicture(KleeFace[Face][Emotion], hdc, Facex + KleeFloatx, Facey + KleeFloaty, Facecx, Facecy);
            }
        }
        if (Tips != NULL && (Centre_x + 300 - KleePlacex + 340) > Start_x && (Centre_x + 300 - KleePlacex) < End_x && (Centre_y - 190 - KleePlacey + 260) > Start_y && (Centre_y - 190 - KleePlacey) < End_y)
            RenderPicture(Tips, hdc, Centre_x + 300 - KleePlacex, Centre_y - 190 - KleePlacey, 340, 260);
        if (Klees_aAttack != 0 && AaAttack_is == aAttack)
            RenderPicture(Klees_aAttack, hdc, AttackPointx[0] - KleePlacex, AttackPointy[0] - KleePlacey, AttackPointcx[0], AttackPointcy[0]);
        else if (Klees_Boom != 0 && AaAttack_is == EndaAttack)
            RenderPicture(Klees_Boom, hdc, AttackPointx[0] - KleePlacex, AttackPointy[0] - KleePlacey, 50, 50);

        swprintf(Xname, _T("%d/16000"), KleeBlood);//血量
        TextOut(hdc, 920, 950, Xname, _tcslen(Xname));
        if (Black != NULL)
            RenderPicture(Black, hdc, 750, 966, 400, 10);
        if (Green != NULL)
            RenderPicture(Green, hdc, 750, 966, KleeBlood / 40, 10);

        if (ReflectExtraMassage) {
            swprintf(Xname, _T("You can use:    F1 To help     F5 To reflect extra massage"));
            TextOut(hdc, 0, 0, Xname, _tcslen(Xname));
            swprintf(Xname, _T("DeBug:%.2f,%.2f"), DeBug, Reflect);
            TextOut(hdc, 0, 20, Xname, _tcslen(Xname));
            swprintf(Xname, _T("KleePlace:(%d,%d)"), KleePlacex / 10, -KleePlacey / 10);
            TextOut(hdc, 0, 40, Xname, _tcslen(Xname));
            swprintf(Xname, _T("KleeWalkFace:%d"), (KleeWalkFacex + KleeWalkFacey));
            TextOut(hdc, 0, 60, Xname, _tcslen(Xname));
            swprintf(Xname, _T("KleeFace:%d"), Face);
            TextOut(hdc, 0, 80, Xname, _tcslen(Xname));
            swprintf(Xname, _T("Emotion:%d"), (Emotion + 1));
            TextOut(hdc, 0, 100, Xname, _tcslen(Xname));
            swprintf(Xname, _T("Time:%ds"), EscapeTime[T_EscapeS]);
            TextOut(hdc, 0, 120, Xname, _tcslen(Xname));
            swprintf(Xname, _T("Time:%ds"), EscapeTime[T_EscapeS]);
            TextOut(hdc, 0, 120, Xname, _tcslen(Xname));
        }
        //////////////////////////////////////////////////////

       /*
       ::BitBlt(hdcOrg,          // Destination DC
           0,  // Starting X offset on destination to paint
           0,   // Starting Y offset on destination to paint
           (int)rcClient.right - rcClient.left,   // Width of image to paint onto destination
           (int)rcClient.bottom - rcClient.top,  // Height of image to paint onto destination
           g_hMemDc,    // Source DC
           0,            // Starting X off on the source to paint from
           0,            // Starting Y off on the source to paint from
           SRCCOPY
       );
       */
        EndPaint(hWnd, &ps);
        //FlushBackBuffer();

    }
    break;

    case WM_TIMER://计时器
        switch (wParam)
        {
        case RCTimer:
            GetClientRect(hWnd, &rc);
            InvalidateRect(hWnd, &rc, TRUE);
            break;
        case RCIPictureTimer:
            for (int i = 0; i < HowMathMonsters; i++) {
                if (pMonster->x - KleePlacex < -5000 || pMonster->x - KleePlacex > 6900 || pMonster->y - KleePlacey < -5000 || pMonster->y - KleePlacey > 5990) {
                    MakeAMonster();
                }
                pMonster++;
            }
            pMonster = &Monster[0];//重置指针
            //RCReplaceRandPoint();
            break;
        case _1sTimer:
            EscapeTime[T_EscapeS]++;
            break;
        case WalkTimer:
            if (EscapeTime[T_Walk] >= 1 && EscapeTime[T_Walk] <= 6)
                KleeFloaty -= 2;
            else if (EscapeTime[T_Walk] >= 8 && EscapeTime[T_Walk] <= 13)
                KleeFloaty += 2;
            else if(EscapeTime[T_Walk] >= 16)
                EscapeTime[T_Walk] = 0;
            EscapeTime[T_Walk]++;
            if (KleeWalkFacex == WALK_RIGHT)
                KleePlacex+=10;
            else if (KleeWalkFacex == WALK_LEFT)
                KleePlacex-=10;
            if (KleeWalkFacey == WALK_DOWN)
                KleePlacey+=10;
            else if (KleeWalkFacey == WALK_UP)
                KleePlacey-=10;
            break;
        case JumpTimer:
            break;
        case AaAttackTimer:
            AaAttack_is = AAttack;
            break;
        case Fire_aAttackTimer:
            if (EscapeTime[T_aAttrack] >= 1 && EscapeTime[T_aAttrack] <= 5)
                AttackPointy[0] -= 6;
            else if (EscapeTime[T_aAttrack] >= 6 && EscapeTime[T_aAttrack] <= 10)
                AttackPointy[0] -= 2;
            else if (EscapeTime[T_aAttrack] >= 14 && EscapeTime[T_aAttrack] <= 18)
                AttackPointy[0] += 2;
            else if (EscapeTime[T_aAttrack] >= 19 && EscapeTime[T_aAttrack] <= 23)
                AttackPointy[0] += 6;
            else if (EscapeTime[T_aAttrack] >= 24 && EscapeTime[T_aAttrack] <= 28)
                AttackPointy[0] += 10;

            if (EscapeTime[T_aAttrack] <= 28) {
                if (AttackFacex == WALK_RIGHT)
                    AttackPointx[0] += 20;
                else if (AttackFacex == WALK_LEFT)
                    AttackPointx[0] -= 20;
                if (AttackFacey == WALK_DOWN)
                    AttackPointy[0] += 20;
                else if (AttackFacey == WALK_UP)
                    AttackPointy[0] -= 20;
            }
            else if (EscapeTime[T_aAttrack] >= 29 && EscapeTime[T_aAttrack] <= 34)
                AaAttack_is = EndaAttack;

            if (EscapeTime[T_aAttrack] >= 33) {
                EscapeTime[T_aAttrack] = 0;
                AaAttack_is = No;
                KillTimer(hWnd, Fire_aAttackTimer);
            }
            EscapeTime[T_aAttrack]++;
            break;
        default:
            break;

        }
        
       
        break;


    case WM_DESTROY:
        EXIT();
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// “关于”框的消息处理程序。
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}


//////////////////////////////////////////////////////////////
/*RCStart_x -5000
RCStart_y -5000
RCEnd_x 6900
RCEnd_y 5990*/
void MakeAMonster() {
    switch (rand() % 2)
    {
    case 0://Slime_Grass
        pMonster->Blood = 10000;
        pMonster->cx = 100;
        pMonster->cy = 50;
        pMonster->EA_ElementAttachment = EA_Grass;
        pMonster->EA_HowMath = 4;
        pMonster->Face = rand() % 2;
        pMonster->Name[Left] = Slime_Grass_Hide[Left];
        pMonster->Name[Right] = Slime_Grass_Hide[Right];
        pMonster->MaxBlood = pMonster->Blood;
        pMonster->State = Hide;
        break;
    case 1://Slime_Ice
        pMonster->Blood = 10000;
        pMonster->cx = 125;
        pMonster->cy = 80;
        pMonster->EA_ElementAttachment = EA_IceFrozen;
        pMonster->EA_HowMath = EA_Infinite;
        pMonster->Face = rand() % 2;
        pMonster->Name[Left] = Slime_Ice[Left];
        pMonster->Name[Right] = Slime_Ice[Right];
        pMonster->MaxBlood = pMonster->Blood;
        pMonster->State = Outgoing;
        break;
    default:
        break;
    }
    while (true) {
        pMonster->x = rand() % 11900 - 5000 + KleePlacex;//-5000~6900
        pMonster->y = rand() % 10990 - 5000 + KleePlacey;//-5000~5990
        if (!((pMonster->x - KleePlacex + pMonster->cx) >= Start_x && (pMonster->x - KleePlacex) <= End_x && (pMonster->y - KleePlacey + pMonster->cy) >= Start_y && (pMonster->y - KleePlacey) <= End_y))//不在视线内刷新
            break;
    }
}
int EA_Reaction(int Attack, int* pEA_ElementAttachment, float* pEA_HowMath, int EA_Attack, float EA_HowMathAttack) {
/*EA_No 0无, EA_Ice 1冰, EA_Fire 2火, EA_Water 3水, EA_IceFrozen 4冻结.仅状态, EA_Electricity 5雷, EA_Wind 6风
, EA_Rock 7岩, EA_WaterAndElectricity 8水雷共存.仅状态, EA_Grass 9草, EA_Burning 11燃烧.仅状态*/
    switch (*pEA_ElementAttachment)
    {
    case EA_No://
        *pEA_ElementAttachment = EA_Attack;
        *pEA_ElementAttachment = EA_HowMathAttack;
    case EA_Ice://
        switch (EA_Attack)
        {
        case EA_Ice:
            *pEA_HowMath = max(*pEA_HowMath, EA_HowMathAttack);
        case EA_Fire:
            Attack *= 2;
            *pEA_HowMath -= (2 * EA_HowMathAttack);
            break;
        case EA_Water:
            *pEA_ElementAttachment = EA_IceFrozen;
            *pEA_HowMath = max(*pEA_HowMath, EA_HowMathAttack);
            break;
        case EA_Electricity:
            *pEA_HowMath -= EA_HowMathAttack;
            Attack += 500;
            break;
        case EA_Wind:
            *pEA_HowMath -= (2 * EA_HowMathAttack);//风系默认从弱弱风算起且克冰水雷火
            Attack += 600;
            break;
        case EA_Rock:
            *pEA_HowMath -= (EA_HowMathAttack / 2);//岩从正常量算被冰水雷火克
            break;
        case EA_Grass:
        default:
            break;
        }
    case EA_Fire:
        switch (EA_Attack)
        {
        default:
            break;
        }
    default:
        *pEA_ElementAttachment = EA_Attack;
        *pEA_ElementAttachment = EA_HowMathAttack;
        break;
    }
    if (*pEA_HowMath <= 0) {
        *pEA_ElementAttachment = EA_No;
        *pEA_HowMath = 0;
    }
    return 1;
}

void MakeRandPoint(int HowMath, bool InReflect){
    if (InReflect) {
        for (int i = 0; i <= HowMath; i++) {
            *pRandPointx = rand() % 11900 - 5000;//-5000~6900
            *pRandPointy = rand() % 10990 - 5000;//-5000~5990
            pRandPointx++;
            pRandPointy++;
        }
    }
    else {
        for (int i = 0; i < HowMath; i++) {
            while (true)
            {
                *pRandPointx = rand() % 11900 - 5000;//-5000~6900
                *pRandPointy = rand() % 10990 - 5000;//-5000~5990
                if (!((*pRandPointx) >= Start_x && (*pRandPointx) <= End_x && (*pRandPointy) >= Start_x && (*pRandPointy) <= End_y))

                    break;//不刷新在视线内
            }
            pRandPointx++;
            pRandPointy++;
            *pLong = *pLong + 1;//长度+
        }
    }
}

void RCReplaceRandPoint() {
    int* pPointx = pRandPointx, * pPointy = pRandPointy;//替换完后再将指针指回原位，方便之后使用
    for (int i = 0; i < Long; i++) {
        pRandPointx--;
        pRandPointy--;
        if (*pRandPointx + KleePlacex < -5000 || *pRandPointx + KleePlacex > 6900 || *pRandPointy + KleePlacey < -5000 || *pRandPointy + KleePlacey > 5990) {
            {
                while (true)//MakeRandPoint(1, FALSE);
                {
                    *pRandPointx = rand() % 11900 - 5000;//-5000~6900
                    *pRandPointy = rand() % 10990 - 5000;//-5000~5990
                    if (!((*pRandPointx) >= Start_x && (*pRandPointx) <= End_x && (*pRandPointy) >= Start_x && (*pRandPointy) <= End_y))
                        break;//不刷新在视线内
                }
            }
        }
    }
    pRandPointx = pPointx;
    pRandPointy = pPointy;
}

void Move(int* px, int* py, int HowMath, int Walk_x, int Walk_y) {
    if (Walk_x == WALK_RIGHT)
        px += HowMath;
    else if (Walk_x == WALK_LEFT)
        py -= HowMath;
    if (Walk_y == WALK_DOWN)
        py += HowMath;
    else if (Walk_y == WALK_UP)
        py -= HowMath;
}

IPicture* GetDisplayImage(LPCTSTR szImagePath)
{
    HANDLE hFile = CreateFile(szImagePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); //从指定的路径szImagePath中读取文件句柄 
    DWORD dwFileSize = GetFileSize(hFile, NULL); //获得图片文件的大小，用来分配全局内存 
    HGLOBAL hImageMemory = GlobalAlloc(GMEM_MOVEABLE, dwFileSize); //给图片分配全局内存 
    void* pImageMemory = GlobalLock(hImageMemory); //锁定内存 
    DWORD dwReadedSize; //保存实际读取的文件大小 
    ReadFile(hFile, pImageMemory, dwFileSize, &dwReadedSize, NULL); //读取图片到全局内存当中 
    GlobalUnlock(hImageMemory); //解锁内存 
    CloseHandle(hFile); //关闭文件句柄 

    IStream* pIStream;//创建一个IStream接口指针，用来保存图片流 
    IPicture* pIPicture;//创建一个IPicture接口指针，表示图片对象 
    CreateStreamOnHGlobal(hImageMemory, false, &pIStream); //用全局内存初使化IStream接口指针 
    OleLoadPicture(pIStream, 0, false, IID_IPicture, (LPVOID*)&(pIPicture));//用OleLoadPicture获得IPicture接口指针 

    //得到IPicture COM接口对象后，你就可以进行获得图片信息、显示图片等操作 
     /*
    OLE_XSIZE_HIMETRIC hmWidth;
    OLE_YSIZE_HIMETRIC hmHeight;
    pIPicture->get_Width(&hmWidth); //用接口方法获得图片的宽和高
    pIPicture->get_Height(&hmHeight);


    int x, int y, int width, int height,
    pIPicture->Render(hDC, x, y, width, height, 0, hmHeight, hmWidth, -hmHeight, NULL); //在指定的DC上绘出图片
    */

    GlobalFree(hImageMemory); //释放全局内存 
    pIStream->Release(); //释放pIStream 
    //pIPicture->Release(); //释放pIPicture 
    return pIPicture;
}

void RenderPicture(IPicture* pIPicture, HDC hdc, int x, int y, int cx, int cy) {

    OLE_XSIZE_HIMETRIC hmWidth;
    OLE_YSIZE_HIMETRIC hmHeight;
    pIPicture->get_Width(&hmWidth); //用接口方法获得图片的宽和高 
    pIPicture->get_Height(&hmHeight);

    pIPicture->Render(hdc, x, y, cx, cy, 0, hmHeight, hmWidth, -hmHeight, NULL); //在指定的DC上绘出图片 

}